<template>
    <div class="listDiv">
        <div class="searchDiv">
            <el-select v-model="obj.req.type" placeholder="所属小程序" class="search_select" style="margin-left: 0;" clearable>
                <el-option v-for="(item,index) in globalData.miniTypeList" :key="index" :label="item.text" :value="item.value" />
            </el-select>
            <span class="btn search" @click="init">搜索</span>
            <span class="btn refresh" @click="obj.req.currentpage=1;init()"></span>
            <div class="searchRight">
                <span class="btn add" @click="add">添加banner</span>
            </div>
        </div>
        <div class="table_box"><div class="table_" id="tb">
            <ul class="head">
                <li class="wcen">banner图</li>
                <li class="wcen">所属小程序</li>
                <li class="wcen">排序</li>
                <!-- <li class="liflex">跳转路径</li> -->
                <li class="wcen">操作</li>
            </ul>
            <div class="body">
                <ul v-for="x in obj.ary" :key="x">
                    <li class="wcen">
                        <el-image  style="width: 40px; height: 40px" class="ml5" fit="cover" :preview-src-list="[proxy.$setting.globalUrl.fileurl+ '/banner/'+ x.img]" :src="proxy.$setting.globalUrl.fileurl+ '/banner/'+ x.img">
                            <template #error>
                                <div class="image-slot">
                                    <el-image  fit="cover" src="https://fuss10.elemecdn.com/e/5d/4a731a90594a4af544c0c25941171jpeg.jpeg"/>
                                </div>
                            </template>
                        </el-image>
                    </li>
                    <li class="wcen">{{proxy.$utils.find(globalData.miniTypeList, x.type)}}</li>
                    <li class="wcen">{{x.sort}}</li>
                    <!-- <li class="liflex">{{x.par}}</li> -->
                    <li class="wcen">
                        <el-button class="edit_btn mr10" type="success" @click="edit(x)">修改</el-button>
                        <DelConfirm class="" @yesClick="del(x)" />
                    </li>
                </ul>
            </div>
        </div>
        </div><Pager :value="obj.req" :init="init" />

        <el-dialog v-model="obj.drawer.design" :title="obj.drawer.designTitle" width="1000px" :close-on-click-modal="false" :destroy-on-close="true">
            <router-view @close="obj.drawer.design = false" @init="init" />
        </el-dialog>
    </div>
</template>

<script setup>
    import { reactive, getCurrentInstance, ref, toRefs, provide, computed } from 'vue'
    import Pager from '@/components/pager.vue'
    import DelConfirm from '@/components/del_confirm.vue'
    let { proxy } = getCurrentInstance()

    let obj = reactive({
        drawer: {
            id:"",
            design: false,
            designTitle: "",
        },
        ary: [],
        req: {
            type: ''
        },
    });
    let init = () => {
        proxy.$ajax({
            url: '/banner/list',
            data: obj.req,
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                obj.ary = d.msg.list
                obj.req.count = d.msg.count
            }
        }).catch(() => { })
    }

    let editId = ref(0)
    provide("id", editId); //不能加.value
    let add = () => {
        obj.drawer.design = true
        obj.drawer.designTitle = "添加banner"
        editId.value = 0;
    }
    let edit = x => {
        obj.drawer.design = true
        obj.drawer.designTitle = "修改banner"
        editId.value = x.id;
    }

    let del = x => {
        proxy.$ajax({
            url: '/banner/delete',
            data: { id: x.id },
            bfLoading: true
        }).then(d => {
            // console.log(d)
            if(d.success){
                proxy.elMessageMixin("删除成功", 'success')
                init()
            }else{
                proxy.elMessageMixin(d.err, 'error')
            }
        }).catch(() => { })
    }
</script>

<style scoped>
    ::-webkit-scrollbar { width:10px; background-color: #FFFFFF; }
    .search_select { margin-left: 5px; width:200px!important; }
    .search_key { width:160px!important; }
    #tb ul li.li2 { width: 60px; }
    #tb ul li.li3 { width: 75px; }
    #tb ul li.li4 { width: 75px; }
    #tb ul li.li4 u { cursor: pointer; }
    #tb ul li.li5 { width: 75px; }
</style>